﻿<Window x:Class="WpfWordsLearner.Views.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ad="clr-namespace:AvalonDock;assembly=AvalonDock"
        xmlns:conv="clr-namespace:WpfWordsLearner.Converters"
        xmlns:e="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:ef="clr-namespace:Microsoft.Expression.Media.Effects;assembly=Microsoft.Expression.Effects"
        xmlns:helpers="clr-namespace:WpfWordsLearner.Helpers"
        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
        xmlns:local="clr-namespace:WpfWordsLearner"
        xmlns:me="clr-namespace:WpfWordsLearner.ViewModels"
        xmlns:models="clr-namespace:WpfWordsLearner.Model"
        xmlns:mvvm="clr-namespace:Catel.Windows.Interactivity;assembly=Catel.MVVM"
        Title="Learning words"
        Width="800"
        Height="520">
	<!--
		<Window.Triggers>
		<EventTrigger RoutedEvent="Closing">
		<BeginStoryboard>
		<Storyboard Duration="00:00:01">
		<
		</Storyboard>
		</BeginStoryboard>
		</EventTrigger>
		</Window.Triggers>
	-->
	<i:Interaction.Triggers>
		<i:EventTrigger EventName="Closing">
			<local:ActionClosing />
			<mvvm:EventToCommand Command="{Binding CloseCommand}" />
		</i:EventTrigger>
	</i:Interaction.Triggers>
	<i:Interaction.Behaviors>
		<mvvm:KeyPressToCommand Key="F"
		                        Command="{Binding HandleKeyFCommand}"
		                        Modifiers="Control" />
		<mvvm:KeyPressToCommand Key="Z"
		                        Command="{Binding HandleKeyZCommand}"
		                        Modifiers="Control" />
	</i:Interaction.Behaviors>
	<DockPanel>
		<DockPanel.Resources>
			<conv:BoolToVisibilityConverter x:Key="BoolToVis" />
		</DockPanel.Resources>
		<Menu x:Name="mainMenu" DockPanel.Dock="Top">
			<MenuItem x:Name="miFile" Header="_File">
				<MenuItem x:Name="miExport"
				          Command="{Binding Path=ExportCommand}"
				          Header="Export"
				          ToolTip="Export words to text file" />
				<MenuItem x:Name="miImport"
				          Command="{Binding Path=ImportCommand}"
				          Header="Import"
				          ToolTip="Import new words from file" />
				<Separator />
				<MenuItem x:Name="miExit"
				          Command="{Binding Path=ExitCommand}"
				          Header="Exit" />
			</MenuItem>
			<MenuItem x:Name="miWords" Header="_Word">
				<MenuItem x:Name="miAddWord"
				          Command="{Binding Path=ClickCommand}"
				          Header="Add word" />
				<MenuItem x:Name="miAddWordRange"
				          Command="{Binding Path=AddWordRangeCommand}"
				          Header="Add word range" />
				<MenuItem x:Name="miTranslate"
				          Command="{Binding Path=TranslateCommand}"
				          Header="Translate" />
				<MenuItem x:Name="miLearning"
				          Command="{Binding Path=LearnCommand}"
				          Header="Learn words" />
				<MenuItem Command="{Binding Path=SelectWordsCommand}" Header="Select words" />
			</MenuItem>
			<MenuItem x:Name="miTest" Header="_Test">
				<MenuItem x:Name="miBegin"
				          Command="{Binding Path=BeginTetsCommand}"
				          Header="Begin test" />
			</MenuItem>
		</Menu>
		<ToolBar x:Name="mainToolBar1" DockPanel.Dock="Top">
			<Button x:Name="btnUndo"
			        Width="15"
			        Height="15"
			        Command="{Binding ReturnBackCommand}"
			        ToolTip="Previous result">
				<Image Source="pack://application:,,/Images/Undo.ico" />
			</Button>
			<Button x:Name="btnRedo"
			        Width="15"
			        Height="15"
			        Command="{Binding UndoCommand}"
			        ToolTip="Undo">
				<Image Source="pack://application:,,/Images/Redo.ico" />
			</Button>
			<Separator />
			<Button x:Name="btnAddTlb"
			        Width="15"
			        Height="15"
			        Command="{Binding Path=ClickCommand}"
			        ToolTip="Add word to storage">
				<Image Source="pack://application:,,/Images/Add.ico" />
			</Button>
			<Button Width="15"
			        Height="15"
			        Command="{Binding Path=LoadDictionaryCommand}"
			        ToolTip="Load dictionary">
				<Image Width="17"
				       Height="15"
				       Source="pack://application:,,/Images/load.jpg" />
			</Button>
			<Button x:Name="btnTestTlb"
			        Width="15"
			        Height="15"
			        Command="{Binding Path=BeginTetsCommand}"
			        ToolTip="Begin test">
				<Image Source="pack://application:,,/Images/docs.png" />
			</Button>
		</ToolBar>
		<Grid DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}, Path=DataContext}">
			<Grid.RowDefinitions>
				<RowDefinition />
				<RowDefinition Height="28" />
				<RowDefinition Height="23" />
			</Grid.RowDefinitions>
			<ad:DockingManager>
				<ad:ResizingPanel Orientation="Horizontal">
					<ad:DockablePane>
						<ad:DockableContent x:Name="dictionariesContent" Title="Dictionaries">
							<TreeView AllowDrop="True"
							          helpers:CommandPropertyHelper.DropCommand="{Binding DropCommand}"
							          ItemsSource="{Binding DirectoryModels}">
								<i:Interaction.Triggers>
									<i:EventTrigger EventName="DragEnter">
										<local:OnDragEnterTigger />
									</i:EventTrigger>
								</i:Interaction.Triggers>
								<TreeView.Resources>
									<HierarchicalDataTemplate DataType="{x:Type models:DirectoryModel}" ItemsSource="{Binding Children}">
										<StackPanel Orientation="Horizontal">
											<Image Width="17"
											       Height="19"
											       Source="pack://application:,,/Images/folder.jpg" />
											<TextBlock Text="{Binding Path=Name}" ToolTip="{Binding Path=FullName}" />
										</StackPanel>
									</HierarchicalDataTemplate>
									<DataTemplate DataType="{x:Type models:FileModel}">
										<Border BorderBrush="Blue">
											<TextBlock>
												<TextBlock.Text>
													<MultiBinding StringFormat="{}{0}, {1} bytes">
														<Binding Path="Name" />
														<Binding Path="Lenght" />
													</MultiBinding>
												</TextBlock.Text>
											</TextBlock>
										</Border>
									</DataTemplate>
								</TreeView.Resources>
								<e:Interaction.Behaviors>
									<local:TreeViewBehavior SelectedItem="{Binding SelectedDictionary, Mode=TwoWay}" />
								</e:Interaction.Behaviors>
								<TreeView.ContextMenu>
									<ContextMenu Width="140">
										<Separator />
										<MenuItem HorizontalAlignment="Center"
										          Command="{Binding CreateNewDictionaryCommand}"
										          Foreground="Blue"
										          Header="Create new..." />
										<MenuItem HorizontalAlignment="Center"
										          Command="{Binding LoadDictionaryCommand}"
										          Foreground="Blue"
										          Header="Load data" />
										<MenuItem HorizontalAlignment="Center"
										          Command="{Binding SaveDictionaryCommand}"
										          Foreground="Blue"
										          Header="Save data..." />
										<MenuItem HorizontalAlignment="Center"
										          Command="{Binding DeleteDictionaryCommand}"
										          Foreground="Blue"
										          Header="Delete data..." />
										<MenuItem HorizontalAlignment="Center"
										          Command="{Binding CompressCommand}"
										          Foreground="Blue"
										          Header="Compress" />
										<MenuItem HorizontalAlignment="Center"
										          Command="{Binding MergeCommand}"
										          Foreground="Blue"
										          Header="Merge..." />
									</ContextMenu>
								</TreeView.ContextMenu>
							</TreeView>
						</ad:DockableContent>
					</ad:DockablePane>
					<ad:DockablePane ad:ResizingPanel.ResizeHeight="100">
						<ad:DockableContent x:Name="wordsContent" Title="Words">
							<DataGrid x:Name="dataWords"
							          AutoGenerateColumns="False"
							          ItemsSource="{Binding Words}"
							          SelectedItem="{Binding SelectedWord}">
								<DataGrid.ItemContainerStyle>
									<Style />
								</DataGrid.ItemContainerStyle>
								<!--  Keyboard.PreviewKeyDown="dataWords_PreviewKeyDown"  -->
								<e:Interaction.Triggers>
									<e:EventTrigger EventName="PreviewMouseLeftButtonDown">
										<local:MouseLeftBDownAction />
									</e:EventTrigger>
									<e:EventTrigger EventName="PreviewMouseMove">
										<local:MouseMoveAction />
									</e:EventTrigger>
									<!--
										<e:EventTrigger EventName="PreviewGiveFeedback">
										<local:OnGiveFeedbackAction />
										</e:EventTrigger>
									-->
								</e:Interaction.Triggers>
								<DataGrid.Columns>
									<DataGridTemplateColumn Header="Coplicated">
										<DataGridTemplateColumn.CellTemplate>
											<DataTemplate>
												<Image x:Name="imgResult"
												       Width="20"
												       Height="20"
												       Source="pack://application:,,,/Images/error2.ico"
												       Visibility="{Binding IsComplicated,
												                            Converter={StaticResource BoolToVis}}" />
											</DataTemplate>
										</DataGridTemplateColumn.CellTemplate>
									</DataGridTemplateColumn>
									<DataGridTemplateColumn Header="Voice" FocusManager.FocusedElement="{Binding ElementName=btnPlVoice}">
										<DataGridTemplateColumn.CellTemplate>
											<DataTemplate>
												<Button Width="25" x:Name="btnPlVoice"
												        Height="23"
												        DataContext="{Binding Path=DataContext,
												                              RelativeSource={RelativeSource Mode=FindAncestor,
												                                                             AncestorType=Window}}">
													<Button.Content>
														<Image Source="pack://application:,,,/Images/voice.jpg" />
													</Button.Content>
													<i:Interaction.Triggers>
														<i:EventTrigger EventName="Click">
															<mvvm:EventToCommand Command="{Binding PlaySoundCommand}" />
														</i:EventTrigger>
													</i:Interaction.Triggers>
												</Button>
											</DataTemplate>
										</DataGridTemplateColumn.CellTemplate>
									</DataGridTemplateColumn>
									<DataGridTextColumn Width="200"
									                    Binding="{Binding Path=EnglishWord}"
									                    Header="English" />
									<DataGridTextColumn Width="290"
									                    Binding="{Binding Path=Translate}"
									                    Header="Translate" />
								</DataGrid.Columns>
								<DataGrid.ContextMenu>
									<ContextMenu>
										<Separator />
										<MenuItem Command="{Binding MarkComplicated}"
										          Foreground="Black"
										          Header="Mark as complicated" />
										<MenuItem Command="{Binding UnmarkComplicated}"
										          Foreground="Black"
										          Header="Unmark as complicated" />
									</ContextMenu>
								</DataGrid.ContextMenu>
							</DataGrid>
						</ad:DockableContent>
					</ad:DockablePane>

				</ad:ResizingPanel>
			</ad:DockingManager>

			<Button x:Name="btnAdd"
			        Grid.Row="1"
			        Width="80"
			        Command="{Binding Path=ClickCommand}"
			        Content="Add" />
			<StatusBar Grid.Row="2">
				<StatusBarItem>
					<TextBlock Text="WordsCount:" />
				</StatusBarItem>
				<StatusBarItem>
					<TextBlock Text="{Binding Path=Words.Count}" />
				</StatusBarItem>
				<StatusBarItem HorizontalAlignment="Right">
					<TextBlock Text="{Binding Path=ComplicatedCount, StringFormat='Complicated count: {0}'}" />
				</StatusBarItem>
			</StatusBar>
		</Grid>
	</DockPanel>
</Window>
